home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1996 #15 / Monster Media Number 15 (Monster Media)(July 1996).ISO / prog_c / cuj0696.zip / DWYER.ZIP / PERMUTE.TST / SETPRMUT.C < prev    next >
C/C++ Source or Header  |  1996-01-08  |  3KB  |  93 lines

  1. /* ============ */
  2. /* setprmut.c    */
  3. /* ============ */
  4. #include <io.h>
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <miscdefs.h>
  8. #include <pmtndefs.h>
  9. #include <mconf.h>
  10.  
  11. #define    ACT(X)    #X
  12.  
  13. #define    CLAMP(Out, Var, Lo, Hi)    Out = __min(Hi, __max(Lo, Var))
  14.  
  15. #define    NEED_ALL(Label)    "Enter "Label
  16.  
  17. #define    NEED_USER_ENTRY(LABEL, LO, HI) \
  18.     NEED_ALL(LABEL" ["ACT(LO)"-"ACT(HI)"]: ")
  19.  
  20. #define    ELEMS_LABEL    "No. Elements Per Permutation"
  21. #define    EXPECT_LABEL    "Expected No. Events for Each Category"
  22.  
  23. #define    REPORT_USER_INT_ENTRY(Entry, Label)        \
  24.     {                            \
  25.     fflush(NULL); printf("\n");            \
  26.     printf("\tNumber Entered:  %.f", (double)Entry);\
  27.     printf(" (%s)\n", Label);            \
  28.     }
  29. #define    SHOW_INT_VALUE_USED(Entered, Used)             \
  30.     printf("\tTest Value Used: %.f%s\n", (double)Used,    \
  31.     ((double)Entered == (double)Used) ? "" : " (Clamped)")
  32.  
  33. /* ==================================================================== */
  34. /* SetPermuteControls - Puts Run Controls in PermuteData structure    */
  35. /* ==================================================================== */
  36. void
  37. SetPermuteControls(PRMUT_DATA_STRU  *PermuteData)
  38. {
  39.     int     NewlineCh;
  40.     int     UserIntEntry;
  41.  
  42.     NewlineCh = _isatty(_fileno(stdin)) ? '\r' : '\n';
  43.  
  44.     /* ------------------------------------------------- */
  45.     /* Get Number of Variates (Elements) Per Permutation */
  46.     /* ------------------------------------------------- */
  47.     GetInt(NEED_USER_ENTRY(ELEMS_LABEL, MIN_ELEMS, MAX_ELEMS),
  48.     &UserIntEntry);
  49.  
  50.     REPORT_USER_INT_ENTRY(UserIntEntry, ELEMS_LABEL);
  51.  
  52.     /* ---------------------------------------- */
  53.     /* Clamp Number of Elements Per Permutation */
  54.     /* ---------------------------------------- */
  55.     CLAMP(PermuteData->NumElements, UserIntEntry, MIN_ELEMS, MAX_ELEMS);
  56.  
  57.     SHOW_INT_VALUE_USED(UserIntEntry, PermuteData->NumElements);
  58.  
  59.     fflush(NULL); fprintf(stderr, "%c", NewlineCh);
  60.     /* ------------------------------------------- */
  61.     /* Calculate Number of Categories in This Test */
  62.     /* ------------------------------------------- */
  63.     PermuteData->NumCategories = (int) fac(PermuteData->NumElements);
  64.  
  65.     printf("%6d  CATEGORIES IN THIS TEST\n", PermuteData->NumCategories);
  66.  
  67.     /* ------------------------ */
  68.     /* Request Cell Expectation    */
  69.     /* ------------------------ */
  70.     GetInt(NEED_USER_ENTRY(EXPECT_LABEL, MIN_CELL_CT, MAX_CELL_CT),
  71.     &UserIntEntry);
  72.  
  73.     REPORT_USER_INT_ENTRY(UserIntEntry, EXPECT_LABEL);
  74.  
  75.     /* ---------------------- */
  76.     /* Clamp Cell Expectation */
  77.     /* ---------------------- */
  78.     CLAMP(PermuteData->CellExpectation, UserIntEntry, MIN_CELL_CT,
  79.     MAX_CELL_CT);
  80.  
  81.     SHOW_INT_VALUE_USED(UserIntEntry, PermuteData->CellExpectation);
  82.  
  83.     fflush(NULL); fprintf(stderr, "%c", NewlineCh);
  84.     /* ----------------------------------------------- */
  85.     /* Calculate Number of Permutations to be Analyzed */
  86.     /* ----------------------------------------------- */
  87.     PermuteData->NumObs = (UINT)
  88.     PermuteData->CellExpectation * PermuteData->NumCategories;
  89.  
  90.     printf("%6u  OBSERVATIONS (PERMUTATIONS) WILL BE ANALYZED\n",
  91.     PermuteData->NumObs);
  92. }
  93.